#include <iostream>
#include <cstring>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/video.hpp>
#include <opencv2/imgproc/imgproc.hpp>


int main(int argc,char** argv)
{
	bool ret = false;

	cv::VideoCapture cap("/home/sunrise/opencv/build/SaveVideo/test.mp4");
	if(!cap.isOpened()){
		std::cout << "can not open video" << std::endl;
		return -1;
	}

	cv::Mat frame;

	while(true)
	{
		cap >> frame;
		if(frame.empty()){
			break;
		}

		cv::imshow("Video",frame);

		if(cv::waitKey(500) == 'q'){
			break;
		}
	}
	
	cap.release();
	cv::destroyAllWindows();
	return 0;
#if 0
	FrameClass* frameObj = new FrameClass();
	if(false == frameObj->OpenVideo(VIDEO_PATH)){
		delete frameObj;
		return 1;
	}

		
	int fps 	= frameObj->capture.get(cv::CAP_PROP_FPS);
	int width 	= frameObj->capture.get(cv::CAP_PROP_FRAME_WIDTH);
	int height 	= frameObj->capture.get(cv::CAP_PROP_FRAME_HEIGHT);
	int type    = frameObj->capture.get(cv::CAP_PROP_FOURCC);

	cv::VideoWriter Vwriter("./SaveVideo/test.mp4",cv::VideoWriter::fourcc('m','p','4','v'),fps,cv::Size(width,height),false);

	while(true)
	{

		if(false == frameObj->ReadImage()){
			delete frameObj;
			return 2;
		}
	
		frameObj->SplitChannels(0);
		frameObj->Blur();
		frameObj->Threshold();
		frameObj->FindContours();
		frameObj->DrawContours();	

		frameObj->ShowSrcImage();
		frameObj->ShowChannelImage();
		frameObj->ShowBinaryImage();

		int val = cv::waitKey(5000);
		if(KEYBOARD_1 == val){
			break;	
		}else if(KEYBOARD_2 == val){
			frameObj->SaveImage();
		}else if(KEYBOARD_3 == val){
			Vwriter.write(frameObj->U8C1Img);
		}
	}

	delete frameObj;	
	return 0;
#endif	
}




